//////////////////////////////////////////////
///                                        ///
/// PPA-1's ALU                            ///
///                                        ///
/// Released under CERN Open Hardware      ///
/// License                                ///
///                                        ///
/// Marce Coll 2017 - ppa@marcecoll.com    ///
///                                        ///
//////////////////////////////////////////////


`include "ppa1_defines.v"

module ppa1_alu(
                a, b, result,
                alu_op
                );

   parameter width = `PPA1_OPERAND_WIDTH;

   input [width-1:0]                a;
   input [width-1:0]                b;
   input [`PPA1_ALUOP_WIDTH-1:0]    alu_op;
   output [width-1:0]               result;

   reg [width-1:0]                  result;

   always @(alu_op or a or b) begin
      casez (alu_op)
        `PPA1_ALUOP_ADDC,
        `PPA1_ALUOP_SUB,
        `PPA1_ALUOP_ADD : begin
           result = a&b;
        end

        `PPA1_ALUOP_XOR : begin
           result = a^b;
        end

        `PPA1_ALUOP_AND : begin
           result = a&b;
        end

        `PPA1_ALUOP_OR : begin
           result = a|b;
        end

        `PPA1_ALUOP_NOP : begin
           result = a;
        end

        default : begin
           result = 0;
        end
      endcase
   end

endmodule // ppa1_alu
